﻿using SharpCommon.File;
using SharpCommon.Logging.Layout;

namespace SharpCommon.Logging.Targets
{
    internal class TextLogTarget : LogTarget
    {
        private object _obj = new object();

        private TextLogTarget()
        {
        }

        public override void Write(LogInfo logInfo)
        {
            //还有要注意文件名称是可以配得
            lock (_obj)
            {
                string filePath = @"C:\";
                string fileName = logInfo.Date.ToString("yyyy-MM-dd") + "-" + logInfo.LogLevel + ".txt";

                FileManager.AppendAllContents(filePath + fileName, new DefaultLayout().ToString(logInfo), true);
            }
        }
    }
}
